home *** CD-ROM | disk | FTP | other *** search
- #include "PICSCompositeDialog.h"
- #include "PICS_PreferencesPanes.h"
-
- #include "PICSViewer.h"
- #include "PICS_Types.h"
- #include "Monitors.h" // For Place()
- #include "KeyUtils.h" // To handle key-down events
-
- #include "icl8 LDEF.h"
-
- // ---------------------------------------------------------------------------
-
- void InitPrefs() {
- PrefsHandle prefs;
-
- prefs = LoadPrefs();
- SetDragAndDropOperation((**prefs).defaultOperation);
- ReleaseResource((Handle)prefs);
- } // END InitPrefs
-
- // ---------------------------------------------------------------------------
-
- PrefsHandle LoadPrefs() {
- PrefsHandle prefs;
-
- prefs = (PrefsHandle)GetResource('PRFS', 128);
- if (prefs == NULL) {
- prefs = (PrefsHandle)NewHandleClear(sizeof(Prefs));
-
- (**prefs).showOpenProgress = kNeverShowOpenProgress; // -1=always; 0=never; n=if bigger than n
- (**prefs).defaultOperation = kPlayOperation;
- (**prefs).compositePreview = true;
- (**prefs).changeCreator = true;
- (**prefs).animationMethod = kUsePictureGWorldMethod;
- (**prefs).pictCreatorType = kPhotoShopCreatorType;
-
- (**prefs).marqueeColor = kMarqueeUseHiliteColor;
- (**prefs).customRGBColor.red =
- (**prefs).customRGBColor.green =
- (**prefs).customRGBColor.blue = 0xFFFF;
-
- (**prefs).composite.doCrop = true;
- (**prefs).composite.doAssemble = true;
- (**prefs).composite.assembleLeftToRight = true;
- (**prefs).composite.outputDepthType = kUsePICSFileOutputDepth;
-
- AddResource((Handle)prefs, 'PRFS', 128, "\pPrefs, dude!");
- WriteResource((Handle)prefs);
- }
- return(prefs);
- } // END LoadPrefs
-
- // ---------------------------------------------------------------------------
-
- void GetPrefsMarqueeColor(PrefsHandle prefs, RGBColor *marqueeColor) {
- switch((**prefs).marqueeColor) {
- case kMarqueeUseHiliteColor:
- LMGetHiliteRGB(marqueeColor);
- break;
-
- case kMarqueeUseBlackColor:
- marqueeColor->red = marqueeColor->green = marqueeColor->blue = 0;
- break;
-
- case kMarqueeUseCustomColor:
- *marqueeColor = (**prefs).customRGBColor;
- break;
- }
- } // END GetPrefsMarqueeColor
-
- // ---------------------------------------------------------------------------
-
- static void DisposePrefsDialog(DialogPtr prefsDlog, Boolean savePrefs);
- static void PrefsDialogHandleHit(DialogPtr prefsDlog, EventRecord *theEvt, short itemHit);
- static Boolean PrefsDialogHandleKey(DialogPtr prefsDlog, EventRecord *theEvt);
- static void PrefsDialogHandleUpdate(DialogPtr prefsDlog, EventRecord *theEvt, Boolean frontMost);
- static void PrefsDialogHandleActivate(DialogPtr prefsDlog, Boolean activate);
-
- static Boolean PrefsDialogGetCurrentPane(DialogPtr prefsDlog);
- static Boolean PrefsDialogSwitchPanes(DialogPtr prefsDlog, short paneID);
- static void PrefsDialogRevertPaneToDefault(DialogPtr prefsDlog);
-
- // ---------------------------------------------------------------------------
-
- PrefsData *sPrefsData = NULL;
-
- static short sPanesChanged;
-
- // ---------------------------------------------------------------------------
-
- void SetupPrefsDialog() {
- DialogPtr prefsDlog;
-
- if (sPrefsData == NULL) {
- sPrefsData = (PrefsData*)NewPtr(sizeof(PrefsData));
- sPrefsData->lastPaneUsed = kFirstPaneID;
- }
-
- // Get a copy of the prefs
- PrefsHandle prefs = LoadPrefs();
- sPrefsData->prefs = prefs;
- HandToHand((Handle*)&sPrefsData->prefs);
- ReleaseResource((Handle)prefs);
-
- prefsDlog = GetNewDialog(kPrefsDlogID, NULL, (WindowPtr)-1);
- SetPort(prefsDlog);
-
- // Setup icon list
- Rect dataBounds;
- Rect listRect;
- Cell cSize;
- IconListData theIcon;
-
- SetRect(&dataBounds, 0, 0, 1, kNumPanes);
- GetDItemRect(prefsDlog, kPrefsDlog_PaneList, &listRect);
- // Accomodate scrollbar
- listRect.right -= 15;
- // Set cell size based on size of list user-item
- SetPt(&cSize, (listRect.right - listRect.left),
- (listRect.bottom - listRect.top)/4);
-
- /*
- If you keep forgetting (like I do ^_^), remember that
- cells are like arrays: 0 is a valid cell index. A cell
- of {0,0} is the topleft cell.
- */
- sPrefsData->paneList = LNew(&listRect, &dataBounds, cSize, kPrefsPaneListDefID,
- prefsDlog, false, false, false, true);
-
- // Set icon parameters here.
- theIcon.iconSize = kIconBasedOnCellSize;
- theIcon.frameWidth = 2;
- theIcon.drawName = true;
- theIcon.selType = kSelectByDarkenIcon;
- theIcon.id = kOpenFilePaneID;
-
- // Add icons to pane list
- for (short i = 0; i < kNumPanes; i++) {
- SetPt(&cSize, 0, i);
- LAddToCell(&theIcon, sizeof(IconListData), cSize, sPrefsData->paneList);
- theIcon.id++;
- }
-
- // Select last pane used & scroll to it if it's not visible
- cSize.h = 0;
- cSize.v = sPrefsData->lastPaneUsed - kFirstPaneID;
- LSetSelect(true, cSize, sPrefsData->paneList);
- LAutoScroll(sPrefsData->paneList);
-
- // Load in current pane
- PrefsDialogSwitchPanes(prefsDlog, sPrefsData->lastPaneUsed);
-
- RegisterMovableModalDialog(prefsDlog,
- PrefsDialogHandleHit,
- PrefsDialogHandleKey,
- PrefsDialogHandleUpdate,
- PrefsDialogHandleActivate,
- NULL);
-
- Place(prefsDlog, kCenterOnDeepDevice);
- LDoDraw(true, sPrefsData->paneList);
- sPanesChanged = false; // Reset to make sure the list is updated
- } // END SetupPrefsDialog
-
- // ---------------------------------------------------------------------------
-
- void DisposePrefsDialog(DialogPtr prefsDlog, Boolean savePrefs) {
- HideWindow(prefsDlog);
-
- if (savePrefs) {
- PrefsHandle prefs = LoadPrefs();
- BlockMove(*(sPrefsData->prefs), *prefs, sizeof(Prefs));
-
- SetPICSViewerAnimationMethod((**prefs).animationMethod);
- RGBColor marqueeColor;
- GetPrefsMarqueeColor(prefs, &marqueeColor);
- SetPICSViewerMarqueeColor(&marqueeColor);
- SetPICSViewerOpenProgress((**prefs).showOpenProgress);
-
- ChangedResource((Handle)prefs);
- WriteResource((Handle)prefs);
- ReleaseResource((Handle)prefs);
- }
-
- LDispose(sPrefsData->paneList);
- DisposeDialog(prefsDlog);
- UnregisterMovableModalDialog(prefsDlog);
- } // END DisposePrefsDialog
-
- // ---------------------------------------------------------------------------
-
- void PrefsDialogHandleHit(DialogPtr prefsDlog, EventRecord *theEvt, short itemHit) {
- switch(itemHit) {
- case kPrefsDlog_CancelBtn:
- DisposePrefsDialog(prefsDlog, false);
- break;
-
- case kPrefsDlog_OKBtn:
- // Make sure all data is valid before closing dialog;
- // also forces current pane to save it's data (in case
- // data is ok)
- if (PrefsDialogGetCurrentPane(prefsDlog))
- DisposePrefsDialog(prefsDlog, true);
- break;
-
- case kPrefsDlog_DefaultBtn:
- PrefsDialogRevertPaneToDefault(prefsDlog);
- break;
-
- case kPrefsDlog_PaneList:
- Point listClick = theEvt->where;
- GlobalToLocal(&listClick);
- // Call LClick(). It returns true only for double clicks;
- // but we need to check for single clicks also, which is why
- // we call LGetSelect() below.
- LClick(listClick, theEvt->modifiers, sPrefsData->paneList);
-
- Cell selectedCell = { 0, 0 };
- if (LGetSelect(true, &selectedCell, sPrefsData->paneList)) {
- // Is selected pane the current pane icon or a new pane icon?
- if (sPrefsData->lastPaneUsed != (selectedCell.v + kFirstPaneID)) {
- if (!PrefsDialogSwitchPanes(prefsDlog, selectedCell.v + kFirstPaneID)) {
- // Unable to change panes; revert to last cell selection
- LSetSelect(false, selectedCell, sPrefsData->paneList);
- selectedCell.h = 0;
- selectedCell.v = sPrefsData->lastPaneUsed - kFirstPaneID;
- LSetSelect(true, selectedCell, sPrefsData->paneList);
- }
- }
- }
- break;
-
- case kPrefsDlog_PaneSeparatorLine:
- break;
-
- default:
- switch(sPrefsData->lastPaneUsed) {
- case kOpenFilePaneID:
- PrefsDialogOpenFilePaneHit(prefsDlog, itemHit);
- break;
- case kDragPaneID:
- PrefsDialogDragPaneHit(prefsDlog, itemHit);
- break;
- case kCompositePaneID:
- PrefsDialogCompositePaneHit(prefsDlog, itemHit);
- break;
- case kAnimPaneID:
- PrefsDialogAnimPaneHit(prefsDlog, itemHit);
- break;
- case kCreatorPaneID:
- PrefsDialogCreatorPaneHit(prefsDlog, itemHit);
- break;
- case kMarqueePaneID:
- PrefsDialogMarqueePaneHit(prefsDlog, itemHit);
- break;
- }
- break;
- }
- } // END PrefsDialogHandleHit
-
- // ---------------------------------------------------------------------------
-
- Boolean PrefsDialogHandleKey(DialogPtr prefsDlog, EventRecord *theEvt) {
- char key = theEvt->message & charCodeMask;
- Boolean handledIt = false;
-
- switch(key) {
- case kReturn_Key:
- PushButton(prefsDlog, kPrefsDlog_OKBtn);
- if (PrefsDialogGetCurrentPane(prefsDlog))
- DisposePrefsDialog(prefsDlog, true);
- handledIt = true;
- break;
-
- case kEscape_Key:
- PushButton(prefsDlog, kPrefsDlog_CancelBtn);
- DisposePrefsDialog(prefsDlog, false);
- handledIt = true;
- break;
- }
-
- return(handledIt);
- } // END PrefsDialogHandleKey
-
- // ---------------------------------------------------------------------------
-
- void PrefsDialogHandleUpdate(DialogPtr prefsDlog, EventRecord *theEvt, Boolean frontMost) {
- Rect lineRect;
- GetDItemRect(prefsDlog, kPrefsDlog_PaneSeparatorLine, &lineRect);
- GrayDrawShadowLine(&lineRect, NULL);
-
- /*
- Slight problem here: every time we switch panes it causes an
- update event. The catch is the LDEF erases & redraws the whole list
- in response to an update event. But since only the pane, not the
- list, changes we get a spurious update event for the list. Thus
- the whole list "flickers" because it's erased & redrawn.
- Solution: whenever the panes change, we set the <sPanesChanged>
- static global. Here at the update routine, we check the global;
- if it's false it means this is a true update event for the list.
- If it's true, the panes have changed only, and we don't need
- to update the list.
- */
- if (sPanesChanged == false) {
- Rect listRect;
- GetDItemRect(prefsDlog, kPrefsDlog_PaneList, &listRect);
- InsetRect(&listRect, -2, -2);
- GrayDrawShadowBox(&listRect, NULL);
- LUpdate(prefsDlog->visRgn, sPrefsData->paneList);
- }
- sPanesChanged = false;
-
- DrawDefaultBorder(prefsDlog, kPrefsDlog_OKBtn);
-
- switch(sPrefsData->lastPaneUsed) {
- case kOpenFilePaneID:
- PrefsDialogOpenFilePaneUpdate(prefsDlog, theEvt, frontMost);
- break;
- case kDragPaneID:
- PrefsDialogDragPaneUpdate(prefsDlog, theEvt, frontMost);
- break;
- case kCompositePaneID:
- PrefsDialogCompositePaneUpdate(prefsDlog, theEvt, frontMost);
- break;
- case kAnimPaneID:
- PrefsDialogAnimPaneUpdate(prefsDlog, theEvt, frontMost);
- break;
- case kCreatorPaneID:
- PrefsDialogCreatorPaneUpdate(prefsDlog, theEvt, frontMost);
- break;
- case kMarqueePaneID:
- PrefsDialogMarqueePaneUpdate(prefsDlog, theEvt, frontMost);
- break;
- }
- } // END PrefsDialogHandleUpdate
-
- // ---------------------------------------------------------------------------
-
- void PrefsDialogHandleActivate(DialogPtr prefsDlog, Boolean activate) {
- short hiliteMode;
-
- if (activate)
- hiliteMode = 0;
- else
- hiliteMode = 255;
-
- for (short i = kPrefsDlog_OKBtn; i <= kPrefsDlog_DefaultBtn; i++) {
- HiliteControl((ControlHandle)GetDItemHdl(prefsDlog, i), hiliteMode);
- }
- DrawDefaultBorder(prefsDlog, kPrefsDlog_OKBtn);
-
- // Not only disable controls, but draw all text in gray too...
- // Note: works only if there are no editText items in the dialog,
- // else the Dialog Manager takes control over the port and
- // resets the textMode (one among many variables it sets and fails
- // to set back for you, rendering the port unusable for useWFont
- // variations of your controls).
- if (!activate) {
- TextMode(grayishTextOr);
- UpdateDialog(prefsDlog, prefsDlog->visRgn);
- }
- else {
- TextMode(srcOr);
- UpdateDialog(prefsDlog, prefsDlog->visRgn);
- }
-
- // We have to call LUpdate here because LActivate affects only
- // the scroll bars & the current cell selection. We need to
- // gray out all cells' text via LUpdate
- LUpdate(prefsDlog->visRgn, sPrefsData->paneList);
- LActivate(activate, sPrefsData->paneList);
-
- switch(sPrefsData->lastPaneUsed) {
- case kOpenFilePaneID:
- PrefsDialogOpenFilePaneActivate(prefsDlog, activate);
- break;
- case kDragPaneID:
- PrefsDialogDragPaneActivate(prefsDlog, activate);
- break;
- case kCompositePaneID:
- PrefsDialogCompositePaneActivate(prefsDlog, activate);
- break;
- case kAnimPaneID:
- PrefsDialogAnimPaneActivate(prefsDlog, activate);
- break;
- case kCreatorPaneID:
- PrefsDialogCreatorPaneActivate(prefsDlog, activate);
- break;
- case kMarqueePaneID:
- PrefsDialogMarqueePaneActivate(prefsDlog, activate);
- break;
- }
- } // END PrefsDialogHandleActivate
-
- // ---------------------------------------------------------------------------
-
- /*
- Makes sure user can switch panes (for example, user might typed in
- an invalid number in an editText field; the PrefsDialogGetxxxPaneSettings()
- would return false, and we don't allow the user to switch panes).
- */
- Boolean PrefsDialogGetCurrentPane(DialogPtr prefsDlog) {
- Boolean canSwitchPane;
-
- // Get current pane settings
- switch(sPrefsData->lastPaneUsed) {
- case kOpenFilePaneID:
- canSwitchPane = PrefsDialogGetOpenFilePaneSettings(prefsDlog);
- break;
- case kDragPaneID:
- canSwitchPane = PrefsDialogGetDragPaneSettings(prefsDlog);
- break;
- case kCompositePaneID:
- canSwitchPane = PrefsDialogGetCompositePaneSettings(prefsDlog);
- break;
- case kAnimPaneID:
- canSwitchPane = PrefsDialogGetAnimPaneSettings(prefsDlog);
- break;
- case kCreatorPaneID:
- canSwitchPane = PrefsDialogGetCreatorPaneSettings(prefsDlog);
- break;
- case kMarqueePaneID:
- canSwitchPane = PrefsDialogGetMarqueePaneSettings(prefsDlog);
- break;
- }
-
- return(canSwitchPane);
- } // END PrefsDialogGetCurrentPane
-
- // ---------------------------------------------------------------------------
-
- Boolean PrefsDialogSwitchPanes(DialogPtr prefsDlog, short paneID) {
- short removeCount;
-
- if (sPrefsData->lastPaneUsed != paneID) {
- // Get current pane settings only if panes have changed
- // (they might not have changed; we could have been called
- // from SetupPrefDialog().
- if (!PrefsDialogGetCurrentPane(prefsDlog))
- return(false);
- }
-
- // Remove current pane DITL
- removeCount = CountDITL(prefsDlog) - kPrefsDlog_LastItem + 1;
- if (removeCount > 0) {
- ShortenDITL(prefsDlog, removeCount);
- }
-
- // Add new pane's DITL
- Handle ditl;
- ditl = GetResource('DITL', paneID);
- if (ditl != NULL) {
- AppendDITL(prefsDlog, ditl, overlayDITL);
- ReleaseResource(ditl);
- }
- sPrefsData->lastPaneUsed = paneID;
-
- // Tell pane to initialize it's items
- switch(paneID) {
- case kOpenFilePaneID:
- PrefsDialogSetupOpenFilePane(prefsDlog);
- break;
- case kDragPaneID:
- PrefsDialogSetupDragPane(prefsDlog);
- break;
- case kCompositePaneID:
- PrefsDialogSetupCompositePane(prefsDlog);
- break;
- case kAnimPaneID:
- PrefsDialogSetupAnimPane(prefsDlog);
- break;
- case kCreatorPaneID:
- PrefsDialogSetupCreatorPane(prefsDlog);
- break;
- case kMarqueePaneID:
- PrefsDialogSetupMarqueePane(prefsDlog);
- break;
- }
-
- sPanesChanged = true;
- return(true);
- } // END PrefsDialogSwitchPanes
-
- // ---------------------------------------------------------------------------
-
- void PrefsDialogRevertPaneToDefault(DialogPtr prefsDlog) {
- switch(sPrefsData->lastPaneUsed) {
- case kOpenFilePaneID:
- (**sPrefsData->prefs).showOpenProgress = kNeverShowOpenProgress;
- PrefsDialogSetupOpenFilePane(prefsDlog);
- break;
-
- case kDragPaneID:
- (**sPrefsData->prefs).defaultOperation = kPlayOperation;
- PrefsDialogSetupDragPane(prefsDlog);
- break;
-
- case kCompositePaneID:
- (**sPrefsData->prefs).compositePreview = true;
- PrefsDialogSetupCompositePane(prefsDlog);
- break;
-
- case kAnimPaneID:
- (**sPrefsData->prefs).animationMethod = kUsePictureGWorldMethod;
- PrefsDialogSetupAnimPane(prefsDlog);
- break;
-
- case kCreatorPaneID:
- (**sPrefsData->prefs).pictCreatorType = kPhotoShopCreatorType;
- PrefsDialogSetupCreatorPane(prefsDlog);
- break;
-
- case kMarqueePaneID:
- (**sPrefsData->prefs).marqueeColor = kMarqueeUseHiliteColor;
- (**sPrefsData->prefs).customRGBColor.red =
- (**sPrefsData->prefs).customRGBColor.green =
- (**sPrefsData->prefs).customRGBColor.blue = 0xFFFF;
- PrefsDialogSetupMarqueePane(prefsDlog);
- break;
- }
- sPanesChanged = true;
- } // END PrefsDialogReverPaneToDefault